<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .hide {
        display: none;
    }

    .c1 {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .5);
        z-index: 99;
        margin-top: 0%;
    }

    .c2 {
        background-color: white;
        position: fixed;
        width: 400px;
        height: 300px;
        top: 50%;
        left: 50%;
        z-index: 100;
        margin-top: -150px;
        margin-left: -200px;
        padding-top: 2%;
        padding-left: 2%;
    }

    #modal p {
        margin-left: 80px;
    }

    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_adhj_t {
        background-color: #254060;
        height: 377px;
        color: white;
        overflow: auto;
    }

    .pa_adhj_but {
        height: 58px;
        line-height: 58px;
        float: right;
        width: 150px;
        font-size: 25px;
        color: white;
        margin-right: 50px;
        text-align: center;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟久泰</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:25%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:15%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>安灯呼叫</p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center">
            <div class="aui-flex-item-12">
                <div class="pa_adhj_but" style="background-color: #D9001B;" onclick="confirm()">
                    确认
                </div>
                <div class="pa_adhj_but" style="background-color: #528302;" onclick="handle()">
                    维修处理
                </div>
                <div class="pa_adhj_but" style="background-color: #F59A23;" id="submitButton" onclick="response()">
                    响应
                </div>
                <div class="pa_adhj_but" style="background-color: #00BFBF;" onclick="call()">
                    呼叫
                </div>
            </div>
        </div>
    </div>
    <div class="aui-flex-col aui-flex-center" style="margin-top: 1%;">
        <div class="aui-flex-item-12">
            <div class="aui-flex-col pa_adhj_t">
                <div class="aui-flex-item-12">
                    <div style="height: 100%;width: 100%;">
                        <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                            <thead>
                                <tr style="text-align: center;color: white;font-size: 15px;height: 40px;">
                                    <td algin='center' style="width:4%;"></td>
                                    <td algin='center' style="width:5%">序号</td>
                                    <td algin='center' style="width:10%">异常类型</td>
                                    <td algin='center' style="width:11%">异常内容</td>
                                    <td algin='center' style="width:10%">故障描述</td>
                                    <td algin='center' style="width:6%">状态</td>
                                    <td algin='center' style="width:15%">呼叫时间</td>
                                    <td algin='center' style="width:7%">呼叫人</td>
                                    <td algin='center' style="width:15%">响应时间</td>
                                    <td algin='center' style="width:7%">处理人</td>
                                    <td algin='center' style="width:10%">处理措施</td>
                                    <td style="display:none;">异常记录编码</td>
                                    <td style="display:none;">异常类型id</td>
                                </tr>
                            </thead>
                            <tbody id="andonDataHtml">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div style="padding-top:2%;"></div>
    <!--弹出备注 -->
    <div id="shade" class="c1 hide"></div>
    <div id="modal" class="c2 hide">
        <p style="margin-left: 10px;font-size: 1rem;font-weight: 500;color: #212121;text-align: center;"></p>
        <ul class="aui-list aui-form-list" style="margin-top: 1%;">
            <li class="aui-list-item" id="chkmrlQtyItem">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 250px">扫描/录入卡号:</div>

                    <div class="aui-list-item-input">
                        <input type="text" placeholder="扫描/录入卡号" id="empNo" />
                    </div>
                </div>
            </li>
        </ul>
        <footer class=" aui-bar aui-bar-tab" style="position: absolute;">
            <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消
            </div>
            <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="responseSave()">确定
            </div>
        </footer>
    </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";
    var shiftName = "";
    var shiftCode = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        console.log(api.pageParam.groupLeader)

        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //班次名称
        shiftName = api.pageParam.shiftName;
        //班次编码
        shiftCode = api.pageParam.shiftCode;
        console.log(shiftName)
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //查询不合格数据
        doSearch();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询产线当天所有呼叫数据
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyAndonData";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                // proddate: api.pageParam.proddate,
                // shiftCode: api.pageParam.shiftCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 13px;height:40px;'>";
                        html += "<td><input name='sub' type='checkbox' /></td>"
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='exceptionTypeName'>" + list[i].exceptionTypeName + "</td>";
                        html += "<td name='exceptionContentName'>" + list[i].exceptionContentName + "</td>";
                        html += "<td name='exceptionRemark'>" + list[i].exceptionRemark + "</td>";
                        if (list[i].nodeState == "待响应") {
                            html += "<td name='nodeState' style='background-color:#7573E6;'>" + list[i].nodeState + "</td>";
                        } else if (list[i].nodeState == "待处理") {
                            html += "<td name='nodeState' style='background-color:#F59A23;'>" + list[i].nodeState + "</td>";
                        } else if (list[i].nodeState == "待关闭") {
                            html += "<td name='nodeState' style='background-color:#D9001B;'>" + list[i].nodeState + "</td>";
                        }
                        else if (list[i].nodeState == "待确认关闭") {
                            html += "<td name='nodeState' style='background-color:#D9001B;'>" + list[i].nodeState + "</td>";
                        } else if (list[i].nodeState == "已关闭") {
                            html += "<td name='nodeState' style='background-color:#528302;'>" + list[i].nodeState + "</td>";
                        }
                        html += "<td name='createDate'>" + list[i].createDate + "</td>";
                        html += "<td name='createId'>" + list[i].createId + "</td>";
                        if (list[i].responseDate == null) {
                            html += "<td name='responseDate'></td>";
                        } else {
                            html += "<td name='responseDate'>" + list[i].responseDate + "</td>";
                        }
                        if (list[i].handleId == null) {
                            html += "<td name='handleId'></td>";
                        } else {
                            html += "<td name='handleId'>" + list[i].handleId + "</td>";
                        }
                        if (list[i].exceptionMeasureName == null) {
                            html += "<td name='exceptionMeasureName'></td>";
                        } else {
                            html += "<td name='exceptionMeasureName'>" + list[i].exceptionMeasureName + "</td>";
                        }
                        html += "<td name='code' style='display:none;'>" + list[i].code + "</td>";
                        html += "<td name='exceptionTypeId' style='display:none;'>" + list[i].exceptionTypeId + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("andonDataHtml"), html);
                } else {
                    $api.html($api.byId("andonDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //呼叫
    function call() {
        api.openWin({
            name: "productionAssemblyAndon_call",
            url: 'productionAssemblyAndon_call.html',
            pageParam: api.pageParam,
        });
    }

    //响应
    function response() {

        if (!clickThrottle()) {
            return;
        }


        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var code = "";
        var nodeState = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            code = row.find("[name='code']").html();
            nodeState = row.find("[name='nodeState']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条表格数据",
                duration: 3000
            });
            return;
        }

        if (nodeState != "待响应") {
            api.toast({
                msg: "请选择一条状态为【待响应】的数据!",
                duration: 3000
            });
            return;
        }
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('modal').classList.remove('hide');
        $("#empNo").focus();
    }

    function Hide() {
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
        document.getElementById('empNo').value = "";
    }

    //响应保存
    function responseSave(code, empNo) {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var code = "";
        var nodeState = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            code = row.find("[name='code']").html();
            nodeState = row.find("[name='nodeState']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条表格数据",
                duration: 3000
            });
            return;
        }

        if (nodeState != "待响应") {
            api.toast({
                msg: "请选择一条状态为【待响应】的数据!",
                duration: 3000
            });
            return;
        }

        var empNo = document.getElementById('empNo').value;
        if (!clickThrottle()) {
            return;
        }


        const submitButton = document.getElementById('submitButton');
        submitButton.style.pointerEvents = "none"; // 禁用提交按钮
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyAndonResponse";
        var data = {
            values: {
                exceptionCode: code,
                empNo: empNo,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });
                    Hide();
                    doSearch();
                } else {
                    submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //处理
    function handle() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var code = "";
        var exceptionTypeId = "";
        var nodeState = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            code = row.find("[name='code']").html();
            exceptionTypeId = row.find("[name='exceptionTypeId']").html();
            nodeState = row.find("[name='nodeState']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条表格数据",
                duration: 3000
            });
            return;
        }

        if (nodeState != "待处理") {
            api.toast({
                msg: "请选择一条状态为【待处理】的数据!",
                duration: 3000
            });
            return;
        }

        var pageParam = api.pageParam;
        pageParam.exceptionCode = code;
        pageParam.exceptionTypeId = exceptionTypeId;

        api.openWin({
            name: "productionAssemblyAndon_handl",
            url: 'productionAssemblyAndon_handl.html',
            pageParam: pageParam,
        });
    }

    //确认关闭
    function confirm() {

        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var code = "";
        var nodeState = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            code = row.find("[name='code']").html();
            nodeState = row.find("[name='nodeState']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条表格数据",
                duration: 3000
            });
            return;
        }

        if (nodeState != "待关闭") {
            api.toast({
                msg: "请选择一条状态为【待关闭】的数据!",
                duration: 3000
            });
            return;
        }

        var pageParam = api.pageParam;
        pageParam.exceptionCode = code;

        api.openWin({
            name: "productionAssemblyAndon_close",
            url: 'productionAssemblyAndon_close.html',
            pageParam: pageParam,
        });
    }

    //刷新按钮
    function refresh() {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        //查询表格数据
        doSearch();

    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>